{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1d10696c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "h\n",
      "Alex\n",
      "['zhichao', 'Jack', 'Alex']\n",
      "Jack\n",
      "['Jack', 'Alex']\n",
      "[]\n",
      "['Jack', 'Alex', 'Marry']\n",
      "['zhichao', 'Jack', 'Alex', 'Marry']\n"
     ]
    }
   ],
   "source": [
    "user_date = \"zhichao||youge||gaojin||linzhiliang\"\n",
    "print(user_date[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "cb2d23eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 引入列表\n",
    "user_date_list = [\"zhichao\", \"Jack\", \"Alex\", \"Marry\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "91566244",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex\n"
     ]
    }
   ],
   "source": [
    "# 从左向右取值（index & slice ）\n",
    "print(user_date_list[2])  # 0为第一个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "62b2843f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['zhichao', 'Jack', 'Alex']\n"
     ]
    }
   ],
   "source": [
    "# 切片 slice ，右边的值取不到，例如[0:3]索引为3的值取不到\n",
    "print(user_date_list[0:3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d27f4f04",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jack\n"
     ]
    }
   ],
   "source": [
    "# 从右向左取值（index & slice ）\n",
    "print(user_date_list[-3]) # -1为第一个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "668783ab",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Jack', 'Alex']\n"
     ]
    }
   ],
   "source": [
    "# 切片 slice ，右边的值取不到，例如[0:3]索引为-1的值取不到\n",
    "print(user_date_list[-3:-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d410dfea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[]\n"
     ]
    }
   ],
   "source": [
    "# 如果取值为空，说明slice写错\n",
    "print(user_date_list[-3:0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "481cbfaf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Jack', 'Alex', 'Marry']\n"
     ]
    }
   ],
   "source": [
    "#如果要去到最后一个值，不能写0，直接忽略不写\n",
    "print(user_date_list[-3:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "159094b7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['zhichao', 'Jack', 'Alex', 'Marry']\n"
     ]
    }
   ],
   "source": [
    "#*重要* 全部选完，两边都不写\n",
    "print(user_date_list[:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f2077f40",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 步长list列表slice ： [start：stop：step]\n",
    "# 如果没有指定开始值，则默认为0；\n",
    "# 如果没有指定结束值，则取列表允许的最大值；\n",
    "# 如果没有指定步长值，则默认步长为1；"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
